﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace DefLib
{
    public class Event
    {
        public static int chois_x=0;
        public static int chois_y=0;
        public static int i_choise=0;
        private static int count = 0;
        private static Point m_old;
        
        private static Queue<KeyboardState> Q_keyEvent = new Queue<KeyboardState>();
        private static Queue<MouseState> Q_mouseEvent = new Queue<MouseState>();

        public static void AddKE(KeyboardState ks)
        {
            Q_keyEvent.Enqueue(ks);
        }
        public static void AddME(MouseState ms)
        {
            Q_mouseEvent.Enqueue(ms);
        }
        public static void ProcessEvent()
        {
            chois_x -= ViewFrame.window.X;
            chois_y -= ViewFrame.window.Y;

            int temp_choise = 0;
            int temp_choise2 = 0;
            MouseState ms = Q_mouseEvent.Dequeue();

            if (((m_old.X - ms.X) * (m_old.Y - ms.Y)) != 0)
            {
                chois_x = ms.X;
                chois_y = ms.Y;
                m_old.X = ms.X;
                m_old.Y = ms.Y;
            }
            
                
                if (ms.LeftButton == ButtonState.Pressed)
                {
                    temp_choise2 = 1;

                    chois_x = ms.X;
                    chois_y = ms.Y;
                    m_old.X = ms.X;
                    m_old.Y = ms.Y;
                }
                else
                    temp_choise2 = 0;
            
            

            KeyboardState ks = Q_keyEvent.Dequeue();
            count%=6;

            if (count == 1)
            {
                if (ks.IsKeyDown(Keys.Up))
                    chois_y -= 100;
                if (ks.IsKeyDown(Keys.Down))
                    chois_y += 100;
                if (ks.IsKeyDown(Keys.Left))
                    chois_x -= 100;
                if (ks.IsKeyDown(Keys.Right))
                    chois_x += 100;

                if (ks.IsKeyDown(Keys.Enter))
                    temp_choise = 1;
                else
                    temp_choise = 0;
            }
            count++;
            if ((temp_choise + temp_choise2) != 0)
                i_choise = 1;
            else i_choise = 0;

            chois_x += ViewFrame.window.X;
            chois_y += ViewFrame.window.Y;

            ViewFrame.update(new Point(chois_x, chois_y));
        }
        public static void PushEvent()
        {
          
        }
    }
}
